package com.apes.fn.server.workDesk.smartHelper.process.inStoreBefore;

import com.alibaba.fastjson.JSONArray;
import com.apes.fn.server.workDesk.smartHelper.process.CommonSmartDataProcess;
import com.alibaba.fastjson.JSONObject;
import com.apes.fn.server.workDesk.utils.SmartHelperUtils;
import com.apes.framework.util.MapUtil;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @program: apes-server
 * @description:
 * @author: czs
 * @create: 2023-06-15 09:48
 **/
@Service
public class ReserveProcess extends CommonSmartDataProcess {

    private static final List<String> LEVEL_LIST = Arrays.asList("smartHelper","inStoreBefore","AppOrderDetail","Reserve");

    @Override
    public List<String> getLevelList() {
        return LEVEL_LIST;
    }

    @Override
    public boolean support(String type) {
        return true;
    }

    @Override
    public String getName() {
        return "预约";
    }

    @Override
    public Map findResultData(JSONObject resultMap) {
        Map result = mapper(
                "id", getLevelList().get(getLevelList().size() - 1),
                "name", getName()
        );
        if (resultMap.containsKey("DEPT_ID")){
            JSONObject response = JSONObject.parseObject(this.invoke("pi.app.ext",
                    MapUtil.mapper("headers",MapUtil.mapper("method","v1/store-data/statistical-data","action","get"),
                            "body",mapper("storeCode",resultMap.getString("DEPT_ID"),"typeList","reservationTimeout,readyToStore,unReservation"))
            ));
            JSONArray array = SmartHelperUtils.appStatisticalDataToJson(response);
            result.put("data",array);
        }

        return result;
    }
}
